package net.stuffrepos.bricknetcenter.database.schema;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import net.stuffrepos.bricknetcenter.http.HttpParser;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
@Entity
@Table(name = "http_request_parser_arguments")
public class HttpRequestParserArgument {

    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(length = 32)
    private String id;
    @Column(length = 4096, name="call_position")    
    private Integer callPosition;
    @Column
    @Enumerated(EnumType.STRING)
    private HttpParser.ValueType valueType;
    @Column(length = 4096)
    private String value;
    @ManyToOne(optional = false)
    @JoinColumn(name = "http_request_id", referencedColumnName = "id")
    private HttpRequest httpRequest;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getCallPosition() {
        return callPosition;
    }

    public void setCallPosition(Integer callPosition) {
        this.callPosition = callPosition;
    }

    public HttpParser.ValueType getValueType() {
        return valueType;
    }

    public void setValueType(HttpParser.ValueType valueType) {
        this.valueType = valueType;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public HttpRequest getHttpRequest() {
        return httpRequest;
    }

    public void setHttpRequest(HttpRequest httpRequest) {
        this.httpRequest = httpRequest;
    }

    public Object getValueObject() {
        if (valueType == null) {
            throw new IllegalStateException("Attribute \"valueType\" is null");
        }
        
        return valueType.stringToObject(value);
    }


}
